package com.lineage.server.model.Instance;

import com.lineage.config.ConfigOther;
import com.lineage.server.model.L1AttackPc;
import com.lineage.server.serverpackets.S_DoActionGFX;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Npc;
import com.lineage.server.utils.CalcExp;
import java.util.ArrayList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1ScarecrowInstance extends L1NpcInstance {
  private static final long serialVersionUID = 1L;
  
  private static final Log _log = LogFactory.getLog(L1ScarecrowInstance.class);
  
  public L1ScarecrowInstance(L1Npc template) {
    super(template);
  }
  
  public void onAction(L1PcInstance player) {
    try {
      L1AttackPc l1AttackPc = new L1AttackPc(player, this);
      if (l1AttackPc.calcHit()) {
        int damage = l1AttackPc.calcDamage();
        if (getNpcId() >= 45001 && getNpcId() <= 45003)
          player.sendPackets((ServerBasePacket)new S_ServerMessage(166, "伤害输出: " + damage)); 
        if (player.getLevel() < ConfigOther.Scarecrowlevel) {
          ArrayList<L1PcInstance> targetList = new ArrayList<>();
          targetList.add(player);
          ArrayList<Integer> hateList = new ArrayList<>();
          hateList.add(Integer.valueOf(1));
          int exp = (int)getExp();
          CalcExp.calcExp(player, getId(), targetList, hateList, exp);
        } 
        broadcastPacketAll((ServerBasePacket)new S_DoActionGFX(getId(), 2));
      } else if (getNpcId() >= 45001 && getNpcId() <= 45003) {
        player.sendPackets((ServerBasePacket)new S_ServerMessage(166, "未命中"));
      } 
      l1AttackPc.action();
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public void onTalkAction(L1PcInstance l1pcinstance) {}
  
  public void onFinalAction() {}
  
  public void doFinalAction() {}
}
